<?php

class App_Form_PDF_Form extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        $this->setEnctype("multipart/form-data");

        $uploadDir = dirname(APPLICATION_PATH) . Zend_Registry::get('config')->pdf->upload->dir;

        $this->_initIssue();

        $uploadElement = new Zend_Form_Element_File('upload');
        $uploadElement->setLabel('PDF:')
            ->setRequired()
            ->setDestination($uploadDir)
            ->addValidators(array(
            new Zend_Validate_File_MimeType('application/pdf'),
        ));

        $this->addElement($uploadElement);

//        $hashElement = new Zend_Form_Element_Hash('token');
//        $this->addElement($hashElement);

        $submitElement = new Zend_Form_Element_Submit('submit');
        $submitElement->setLabel('Save')
            ->setAttrib('class', 'btn btn-primary');
        $this->addElement($submitElement);
    }

    private function _initIssue()
    {
        $issueManager = new \Managers\Issue();
        $issues = $issueManager->getList();
        $issueElement = new \Zend_Form_Element_Select('issue');
        foreach ($issues as $issue) {
            $issueElement->addMultiOption($issue['id'], $issue['name']);
        }
        $issueElement->setLabel('Номер журнала:')
            ->setRequired();
        $this->addElement($issueElement);
    }
}
